﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;

namespace RTNLip.Scripts
{
    class RTNSQLDataType
    {
        public static string getSqlString<T>()
        {
            Type t = typeof(T);
            string sqlText = "";
            FieldInfo[] fields = t.GetFields();
            foreach(FieldInfo f in fields)
                sqlText += getSqlStringType(f);
            return sqlText;
        }
        public static string getSqlStringType(FieldInfo f)
        {
            if (f.FieldType == typeof(long))
                return "bigint";
            else if (f.FieldType == typeof(byte[]))
                return "binary";
            else if (f.FieldType == typeof(Boolean))
                return "bit";
            else if (f.FieldType == typeof(DateTime))
                return "date";
            else if (f.FieldType == typeof(DateTimeOffset))
                return "DATETIMEOFFSET";
            else if (f.FieldType == typeof(Decimal))
                return "decimal";
            else if (f.FieldType == typeof(Double))
                return "float";
            else if (f.FieldType == typeof(Int32))
                return "int";
            else if (f.FieldType == typeof(String))
                return "nchar";
            else if (f.FieldType == typeof(char[]))
                return "nvarchar";
            else if (f.FieldType == typeof(Single))
                return "real";
            else if (f.FieldType == typeof(Int16))
                return "smallint";
            else if (f.FieldType == typeof(Object))
                return "sql_variant";
            else if (f.FieldType == typeof(TimeSpan))
                return "time";
            else if (f.FieldType == typeof(Byte))
                return "tinyint";
            else if (f.FieldType == typeof(Guid))
                return "uniqueidentifier";
            return null;
        }  
    }
}
